<?php

class AttributeModel extends Model {

    protected $_logic_table = 'attribute';

    public function getAttrs($type_id) {
        if($type_id == 0) {
            $sql = "SELECT a.*, b.type_name FROM {$this->_table} AS a INNER JOIN cz_goods_type AS b ON a.type_id = b.type_id";
        }
        else {
            $sql = "SELECT a.*, b.type_name FROM {$this->_table} AS a INNER JOIN cz_goods_type AS b ON a.type_id = b.type_id WHERE a.type_id = $type_id";
        }
        return $this->_dao->getAll($sql);
    }

    public function getPageAttrs($type_id, $offset, $pagesize) {
        if($type_id == 0) {
            $sql = "SELECT a.*, b.type_name FROM {$this->_table} AS a INNER JOIN cz_goods_type AS b ON a.type_id = b.type_id LIMIT $offset, $pagesize";
        }
        else {
            $sql = "SELECT a.*, b.type_name FROM {$this->_table} AS a INNER JOIN cz_goods_type AS b ON a.type_id = b.type_id WHERE a.type_id = $type_id LIMIT $offset, $pagesize";
        }
        return $this->_dao->getAll($sql);
    }
}